<template lang="jade">
  #app
    .header
      a.backup.icon-angle-left(v-if='!isTop', @click='goback')
      h1.page-title {{ $route.meta.title }}
    .weui-tab
      router-view.weui-tab__panel(v-if="ready")
    tabbar
</template>

<script>
import Tabbar from './components/Tabbar'
import { mapActions } from 'vuex'

export default {
  name: 'app',
  components: {
    Tabbar
  },
  data () {
    return {
      isTop: true,
      ready: true,
      lastRoute: null
    }
  },
  mounted () {
    this.initSession()
  },
  methods: {
    initSession () {
      // const loginId = this.$cookie.get('wxid')
      const loginId = window.localStorage.getItem('loginId', loginId)
      if (loginId) {
        this.$weui.toast.loading()
        this.getUserInfo({ loginId, loginType: 'RDID' }).then(() => {
          this.$weui.toast.hide()
        })
      }
    },
    goback () {
      this.$router.go(-1)
      // this.lastRoute && this.$router.replace({ path: this.lastRoute })
    },
    ...mapActions(['getUserInfo'])
  },
  watch: {
    $route (to, from) {
      // window.alert(to.path)
      this.isTop = /^\/(home|search|account)(\/)?$/.test(to.path)
      this.lastRoute = from.fullPath
    }
  }
}
</script>

<style lang="scss">
html,
body {
  font-family: 'Avenir', Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  margin: 0;
  padding: 0;
}

html, body, #app {
  height: 100%;
}

* {
  -webkit-touch-callout:none;
  -webkit-user-select:none;
  -moz-user-select:none;
  -ms-user-select:none;
  user-select:none;
}

input,
textarea,
.selectable {
    -webkit-touch-callout:default;
    -webkit-user-select:text;
    -moz-user-select:text;
    -ms-user-select:text;
    user-select:text;
}



.ios {
  .header {
    top: 20px;
    z-index: 100;
    &:before {
      content: '';
      position: fixed;
      top: 0;
      left: 0;
      right: 0;
      height: 20px;
      background-color: #0971ce;
    }
  }
  .weui-tab {
    padding-top: 60px;
  }
}
</style>
